{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "6f0f756c",
   "metadata": {},
   "source": [
    "---\n",
    "* 2023-10-11\n",
    "* 课程：Python语言\n",
    "* week04（第四次课）\n",
    "---\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fc76d97f",
   "metadata": {},
   "source": [
    "# 1. 本周内容\n",
    "## 1. 数值\n",
    "## 2. 字符串\n",
    "## 3. range()函数\n",
    "## 4. for循环"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "dbca1a1b",
   "metadata": {},
   "source": [
    "# 2. 数值\n",
    "\n",
    "> 1. [数值的概念--Python教程](https://docs.python.org/zh-cn/3/tutorial/index.html)\n",
    "> 2. [数值的总结--Python参考](https://docs.python.org/zh-cn/3/library/index.html)\n",
    "> 3. 数值的分类（type）\n",
    ">> 1. int\n",
    ">> 2. float\n",
    ">> 3. complex"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "fb86baa1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "2+2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "ea69af1f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "20"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "50 - 5 * 6"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "c76c811b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1.6"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "8/5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "dc04b46c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "17//3 # 取整"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "695a18d2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "17 % 3 # 取余"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "3f4140b9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "25"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "5 ** 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "95184053",
   "metadata": {},
   "outputs": [],
   "source": [
    "width = 20\n",
    "height = 45"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "8d3e42fb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "900"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "width * height"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "a7924229",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "8"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 数值的方法\n",
    "abs(-8)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "104717a7",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 数值类型\n",
    "\n",
    "a = 2023"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "07068a43",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "int"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "194aaa39",
   "metadata": {},
   "outputs": [],
   "source": [
    "PI = 3.1415926"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "92ab7af0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "float"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(PI)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "a22d3757",
   "metadata": {},
   "outputs": [],
   "source": [
    "b = 3+2j"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "7cca07be",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "complex"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(b)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "37565a92",
   "metadata": {},
   "source": [
    "# 3. 字符串\n",
    "\n",
    "> 1. 字符串的概念与形态\n",
    "> 2. 字符串的一般方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "8ab250b7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'span eggs'"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'span eggs'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "02bc0b76",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Paris rabbit got youe back:)!Yay!'"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"Paris rabbit got youe back:)!Yay!\""
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3fb38c3b",
   "metadata": {},
   "source": [
    "* 笔记：如果引号里面是数值，其结果仍为字符串"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "c476463f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'1975'"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'1975'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "41c529f7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "str"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type('1975')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "06bb09f4",
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "unterminated string literal (detected at line 1) (3342586479.py, line 1)",
     "output_type": "error",
     "traceback": [
      "\u001b[0;36m  Cell \u001b[0;32mIn[20], line 1\u001b[0;36m\u001b[0m\n\u001b[0;31m    ' doesn't '\u001b[0m\n\u001b[0m              ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m unterminated string literal (detected at line 1)\n"
     ]
    }
   ],
   "source": [
    "' doesn't '"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "63fed28e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"doesn't\""
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"doesn't\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "a7db1fab",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 字符串的重要特征：序列\n",
    "\n",
    "地址 = \"广州市从化区温泉大道882号广州南方学院\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "70e9240c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州市从化区温泉大道882号广州南方学院'"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "地址"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cee9732b",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 序列实践\n",
    "# 序列：自然数顺序从左到右依次排序（从0开始）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "c86ca538",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广'"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "地址[0] # 取值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "df2c1eba",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'从化'"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "地址[3:5] # 切片"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "72e7a1cc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'院'"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "地址[-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "48bf621d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'学院'"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#请用负数取出来“学院”\n",
    "地址[-2:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "cee6cd07",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "地址.count(\"广州\") # 取字数出现的次数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a4ed7054",
   "metadata": {},
   "outputs": [],
   "source": [
    "## 通过上面的方法尝试输出”温泉大道“"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b01fc826",
   "metadata": {},
   "source": [
    "# 4. for循环 和 range()语句"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "30ad0480",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "广,\n",
      "州,\n",
      "市,\n",
      "从,\n",
      "化,\n",
      "区,\n",
      "温,\n",
      "泉,\n",
      "大,\n",
      "道,\n",
      "8,\n",
      "8,\n",
      "2,\n",
      "号,\n",
      "广,\n",
      "州,\n",
      "南,\n",
      "方,\n",
      "学,\n",
      "院,\n"
     ]
    }
   ],
   "source": [
    "# i为item, 把如下的操作称为：循环遍历\n",
    "for i in 地址:\n",
    "    print(i + \",\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e0ad763a",
   "metadata": {},
   "source": [
    "* 笔记：range()可以确定范围，并且确定for循环的次数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "3a7e1c0a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "1\n",
      "2\n",
      "3\n",
      "4\n",
      "5\n",
      "6\n",
      "7\n",
      "8\n",
      "9\n",
      "10\n",
      "11\n",
      "12\n",
      "13\n",
      "14\n",
      "15\n",
      "16\n",
      "17\n",
      "18\n",
      "19\n"
     ]
    }
   ],
   "source": [
    "for i in range(20):\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "f20b866c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hello\n",
      "hello\n",
      "hello\n",
      "hello\n",
      "hello\n",
      "hello\n",
      "hello\n",
      "hello\n",
      "hello\n",
      "hello\n",
      "hello\n",
      "hello\n",
      "hello\n",
      "hello\n",
      "hello\n",
      "hello\n",
      "hello\n",
      "hello\n",
      "hello\n",
      "hello\n"
     ]
    }
   ],
   "source": [
    "for i in range(20):\n",
    "    print(\"hello\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "bd3b920a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "10\n",
      "11\n",
      "12\n",
      "13\n",
      "14\n",
      "15\n",
      "16\n",
      "17\n",
      "18\n",
      "19\n"
     ]
    }
   ],
   "source": [
    "for i in range(10,20):\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7ac253e9",
   "metadata": {},
   "source": [
    "## for循环实践\n",
    "### 实践一：创建学号"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "id": "ebdfde6d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "202301030101\n",
      "202301030102\n",
      "202301030103\n",
      "202301030104\n",
      "202301030105\n",
      "202301030106\n",
      "202301030107\n",
      "202301030108\n",
      "202301030109\n",
      "202301030110\n",
      "202301030111\n",
      "202301030112\n",
      "202301030113\n",
      "202301030114\n",
      "202301030115\n",
      "202301030116\n",
      "202301030117\n",
      "202301030118\n",
      "202301030119\n",
      "202301030120\n",
      "202301030121\n",
      "202301030122\n",
      "202301030123\n",
      "202301030124\n",
      "202301030125\n",
      "202301030126\n",
      "202301030127\n",
      "202301030128\n",
      "202301030129\n",
      "202301030130\n",
      "202301030131\n",
      "202301030132\n",
      "202301030133\n",
      "202301030134\n",
      "202301030135\n",
      "202301030136\n",
      "202301030137\n",
      "202301030138\n",
      "202301030139\n",
      "202301030140\n",
      "202301030141\n",
      "202301030142\n",
      "202301030143\n",
      "202301030144\n",
      "202301030145\n",
      "202301030146\n",
      "202301030147\n",
      "202301030148\n",
      "202301030149\n",
      "202301030150\n",
      "202301030151\n",
      "202301030152\n",
      "202301030153\n",
      "202301030154\n",
      "202301030155\n",
      "202301030156\n",
      "202301030157\n",
      "202301030158\n",
      "202301030159\n"
     ]
    }
   ],
   "source": [
    "for i in range(1,60):\n",
    "    if i > 9:\n",
    "        print(\"2023010301\" + str(i))\n",
    "    else:\n",
    "        print(\"20230103010\" + str(i))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "30b7a487",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
